package com.banyiyi.simple.pattern.unsafe;

import sun.misc.Unsafe;

import java.lang.reflect.Field;

/**
 * @ClassName UnsafeDemo
 * @Description 对于unsafe相关操作的测试
 * @Author yangwm
 * @Date 2023/2/16 10:10
 * @Version 1.0
 */
public class UnsafeDemo {

    public static void main(String[] args) {

        Unsafe unsafe = getInstance();
        System.out.println(unsafe);

    }

    public static Unsafe getInstance() {
        try {
            Field field = Unsafe.class.getDeclaredField("theUnsafe");
            field.setAccessible(true);
            return (Unsafe)field.get(null);
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        return null;
    }

}
